<template>
  <view class="chat-position" @click="handleClick">
    <view class="position-header">
      <view class="position-name">{{ data.name }}</view>
      <view class="position-actPrice">¥{{ data.salary }}</view>
    </view>
    <view class="position-company">
      {{ data.company }} ・ {{ data.city }} {{ data.companySize }}</view>
    <view class="position-keywords">
      <view class="position-keywords-item" v-for="item in keywords" :key="item">{{ item }}</view>
    </view>
  </view>
</template>
<script>
export default {
  name: 'WorkMessage',
  props: {
    item: {
      type: Object,
      default: () => ({
        avatar: '',
        flow: 'out',
        m_data: {}
      }),
      required: true
    }
  },
  computed: {
    data() {
      return this.item.m_data
    },
    keywords() {
      let _keywords = []
      if (Array.isArray(this.data.keywords)) {
        _keywords = this.data.keywords
      }
      _keywords = this.data.keywords?.split(',') || []
      return _keywords.filter((item) => item)
    }
  },
  methods: {
    handleClick() {
      if (this.data.id) {
        uni.navigateTo({
          url: `/pages/position/detail?positionId=${this.data.id}`
        });
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.chat-position {
  margin-top: 6px;
  padding: 12px;
  width: auto;
  background: #FFFFFF;
  box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.04);
  border-radius: 8px 8px 8px 0;
  //max-width: 270px;

  .position-header {
    display: flex;
    align-items: center;
    gap: 6px;

    .position-name {
      font-weight: 400;
      font-size: 16px;
      color: #333333;
    }

    .position-actPrice {
      display: inline-block;
      color: #2fb39a;
    }
  }

  .position-company {
    margin-top: 6px;
    font-size: 0.9em;
  }

  .position-keywords {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 6px;

    .position-keywords-item {
      display: inline-block;
      padding: 2px 8px;
      border-radius: 4px;
      width: auto;
      background-color: #f5f5f5;
    }
  }
}
</style>
